package com.codef.sharp.user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codef.sharp.common.core.response.ResponseEntity;
import com.codef.sharp.user.entity.UserEntity;
import com.codef.sharp.user.service.UserService;
import com.codef.sharp.user.vo.UserQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;



/**
 * 用户基础信息控制层
 *
 * @author zhanrf
 * @date 2022-02-12 19:22:50
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 分页查询
     */
    @GetMapping("/list")
    public ResponseEntity<Page<UserEntity>> listPage(UserQueryVo queryVo){
        Page<UserEntity> page = userService.getByPage(queryVo);
        return ResponseEntity.success(page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public ResponseEntity<UserEntity> info(@PathVariable("id") Long id){
		UserEntity user = userService.getById(id);

        return ResponseEntity.success(user);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public ResponseEntity<Void> save(@RequestBody UserEntity user){
		userService.save(user);

        return ResponseEntity.success();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public ResponseEntity<Void> update(@RequestBody UserEntity user){
		userService.updateById(user);

        return ResponseEntity.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public ResponseEntity<Void> delete(@RequestBody Long[] ids){
		userService.removeByIds(Arrays.asList(ids));

        return ResponseEntity.success();
    }

}
